<template>
  <el-card class="box-card" v-loading="loading">
    <div slot="header" class="clearfix">
      <span>财务信息</span>
    </div>
    <div class="app-container">
      <el-form :inline="true" :model="form" ref="refForm" class="demo-form-inline">
        <el-form-item label="查询时间" prop="search_date">
          <el-date-picker
            v-model="form.time"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            :picker-options="pickerDayStep">
          </el-date-picker>
        </el-form-item>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="submitFilter">搜索</el-button>
      </el-form>
    </div>
    <el-table :data="[tableData]" class="el-table-align-center">
      <el-table-column label="存款">
        <el-table-column label="次数" prop="rechargeNum"></el-table-column>
        <el-table-column label="总额">
          <template slot-scope="{row}">
            {{row.rechargeSum | currency}}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="取款">
        <el-table-column label="次数" prop="withdrawNum"></el-table-column>
        <el-table-column label="总额">
          <template slot-scope="{row}">
            {{row.withdrawSum | currency}}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="返水" prop="rebateSum">
        <template slot-scope="{row}">
          {{row.rebateSum | currency}}
        </template>
      </el-table-column>
      <el-table-column label="红利">
        <template slot-scope="{row}">
          {{row.bonusSum | currency}}
        </template>
      </el-table-column>
      <el-table-column label="总投注">
        <template slot-scope="{row}">
          {{row.bettingSum | currency}}
        </template>
      </el-table-column>
      <el-table-column label="总派彩">
        <template slot-scope="{row}">
          {{row.prizeSum | currency}}
        </template>
      </el-table-column>
      <el-table-column label="公司输赢">
        <template slot-scope="{row}">
          {{-1 * row.winSum | currency}}
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script>
  import {getMemberFinance} from "@/services/api/member";
  import formFilter from './formFilter'
  import {grid, pickerOption} from '@/build'

  export default {
    name: "user-finance",
    components: {formFilter},
    mixins: [grid, pickerOption],
    data() {
      //  let times = _.toPeriod({
      //   start: [-1, 'days'],
      //   end: [0, 'days'],
      //   format: 'YYYY-MM-DD'
      // });
      // 本周 即 当前周 周一至今
      const weekTime = [moment().startOf('isoWeek').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')]

      return {
        loading: false,
        colConfigs: [],
        tableData: {},
        form: {
          time: weekTime,
        },
        filters: {
          userId: this.$store.state.member.member_id,
          stime: moment(weekTime[0]).valueOf(),
          etime: moment(weekTime[1]).valueOf() +  86399999,
        }
      }
    },
    mounted() {
      this.bindGet(getMemberFinance, 'tableData', {
        action: 'getGrid',
        sendingData: 'filters'
      })

      this.getAll()

    },
    methods: {
      submitFilter() {
        const {time} = this.form;
        let stime = undefined, etime = undefined;
        if (!_.isUndefined(time) && _.isArray(time)) {
          stime = moment(time[0]).valueOf();
          etime = moment(time[1]).valueOf() +  86399999;
        }

        this.filters = {...this.filters, stime, etime}
        this.gridSearch()
      },
    }
  }
</script>

<style lang="scss">

  .el-table-no-head {
    .el-table__header-wrapper {
      display: none;
    }
  }

</style>
